//
//  DXWNavigationController.m
//  pandaTV
//
//  Created by 淡馨慰 on 16/8/19.
//  Copyright © 2016年 淡馨慰. All rights reserved.
//

#import "DXWNavigationController.h"
#import "UIBarButtonItem+DXWBarButtonItem.h"
#import "DXWSearchViewController.h"

@interface DXWNavigationController ()

@end

@implementation DXWNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1. 设置navigationBar属性
    [self setValueFornavigationBar];
    
}

- (void)loadView
{
    [super loadView];
    
    //一次性设置navigationBar标题
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
//        NSLog(@"%s",__func__);
        NSDictionary *attr = @{
                               NSFontAttributeName : [UIFont systemFontOfSize:17]
                               };
        [[UINavigationBar appearance] setTitleTextAttributes:attr];
    });
  
    
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{

    if (self.childViewControllers.count == 0) {
        //根控制器,统一设置右侧搜索按钮
        //viewController ->子控制器     self -> navigationController
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"searchbutton"] higtLightedImage:[UIImage imageNamed:@"searchbutton_sel"] target:self action:@selector(searchBtnClick)];
    }
    else
        {
            viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageWithOriginalImageName:@"setting_back"] target:self action:@selector(backBtnClick)];
    
        }
    [super pushViewController:viewController animated:animated];

}

#pragma mark -navigationBar属性
- (void)setValueFornavigationBar
{
    //设置背景色
    [[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"tabbar_shadow_bkg"]];
//    self.navigationBar.shadowImage = [UIImage imageNamed:@"tabbar_shadow_bkg"];
//    [self.navigationBar setShadowImage:[UIImage imageNamed:@"tabbar_shadow_bkg"]];

}
#pragma mark -navigationBar左右按钮点击
- (void)searchBtnClick
{
    NSLog(@"searchBtnClick--%@",[self class]);
    DXWSearchViewController *searchVC = [[DXWSearchViewController alloc]init];
    searchVC.hidesBottomBarWhenPushed = YES;
    [self pushViewController:searchVC animated:YES];
    
}

- (void)backBtnClick
{
    NSLog(@"backBtnClick--%@",[self class]);
    [self popViewControllerAnimated:YES];
}



@end
